home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Madness 2 #12 / Multimedia Madness - Volume 2 - Issue 12 (SAMS Publishing) (November 25, 1992).iso / nemo / mewldemo / mewldemo.c < prev    next >
C/C++ Source or Header  |  1992-03-24  |  65KB  |  2,033 lines

  1. #if 0
  2. #define MODELESSTEST
  3. #define CTLCOLOR_TEST
  4. #endif
  5.  
  6. /*===========================================================================*/
  7. /*                                                                           */
  8. /* File    : MEWLDEMO.C                                                      */
  9. /*                                                                           */
  10. /* Purpose : General purpose demo of the MEWEL Window Library                */
  11. /*                                                                           */
  12. /* History :                                                                 */
  13. /*                                                                           */
  14. /* (C) Copyright 1989 Marc Adler/Magma Systems     All Rights Reserved       */
  15. /*===========================================================================*/
  16.  
  17. #include <ctype.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <fcntl.h>
  21. #include <limits.h>
  22. #ifndef UNIX
  23. #include <io.h>
  24. #include <dos.h>
  25. #endif
  26. #include "window.h"
  27.  
  28. typedef long (PASCAL *TIMERPROC)();
  29.  
  30. #define ID_MENUBAR    10
  31. #define ID_NOTEPAD    12
  32. #define ID_ABOUT      98
  33. #define ID_COMBOBOX   97 
  34. #define ID_EXIT       99
  35.  
  36. #define ID_LISTDEMO   200
  37. #define ID_TIMEDEMO   201
  38. #define ID_MOUSEDEMO  202
  39. #define ID_MENUDEMO   203
  40. #define ID_FILEDEMO   204
  41. #define ID_EDITDEMO   205
  42. #define ID_EXECDEMO   206
  43. #define ID_CALCDEMO   207
  44. #define ID_CHILDDEMO  208
  45. #define ID_GRAPHICS   213
  46. #define ID_TOGGLEEGA  214
  47.  
  48. #define ID_COMBODEMO  210
  49.  
  50.  
  51. #define ID_STRING     100
  52. #define ID_POS        101
  53. #define ID_FRAME      102
  54. #define ID_APPEND     103
  55. #define ID_INSERT     104
  56. #define ID_DELETE     105
  57. #define ID_LISTBOX    106
  58.  
  59. #define ID_STOP       100
  60. #define ID_START      101
  61. #define ID_INTERVAL   105
  62.  
  63. #define ID_WORD50     300
  64. #define ID_WRITE      301
  65. #define ID_EXCEL      302
  66. #define ID_124        303
  67. #define ID_C52        304
  68. #define ID_QUICKC     305
  69. #define ID_QUICKBASIC 306
  70. #define ID_PASCAL     307
  71.  
  72. #define ID_NEW    200
  73. #define ID_OPEN   201
  74. #define ID_SAVE   202
  75. #define ID_SAVEAS 203
  76. #define ID_HELP   299
  77.  
  78. #define ID_COPY   510
  79. #define ID_CUT    511
  80. #define ID_PASTE  512
  81. #define ID_CLEAR  513
  82.  
  83. #define ID_GETLEN    520
  84. #define ID_GETLINES  521
  85. #define ID_GETHANDLE 522
  86.  
  87. #define IDM_MEMAVAIL  600
  88.  
  89. #define IDS_MAINTITLE 500
  90.  
  91. #ifdef __TURBOC__
  92. #include <alloc.h>
  93. extern unsigned _stklen = 20000;
  94. #endif
  95.  
  96. typedef struct dlgTemplate
  97. {
  98.   BYTE  *szClass;
  99.   BYTE  *szTitle;
  100.   DWORD dwStyle;
  101.   int   x, y, width, height;
  102.   WORD  idCtrl;
  103. } DTEMPLATE;
  104.  
  105. /*
  106.   A dialog box definition for creating dialog boxes on-the-fly
  107. */
  108. DTEMPLATE IntervalDialogTemplate[] =
  109. {
  110.   { (PSTR) "Text",        (PSTR) "Interval:",    0x0000,         27,10, 9, 1, 0        },
  111.   { (PSTR) "Edit",        (PSTR) NULL,           WS_BORDER | WS_TABSTOP | WS_GROUP, 38,10, 6, 1,ID_INTERVAL},
  112.   { (PSTR) "PushButton",  (PSTR) "~OK",          BS_DEFAULT | WS_TABSTOP | WS_GROUP,30,12, 4, 1,IDOK      },
  113.   { (PSTR) "PushButton",  (PSTR) "~CANCEL",      WS_TABSTOP | WS_GROUP,     39,12, 8, 1,IDCANCEL  },
  114. };
  115.  
  116.  
  117. /*
  118.   Function declarations
  119. */
  120. extern  int main(int argc,char * *argv);
  121. extern  int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
  122. extern  BOOL InitApp(HANDLE hInstance);
  123. extern  LONG PASCAL MainWndProc(HWND hWnd,WORD message,WORD wParam,LONG lParam);
  124. extern  LONG PASCAL NotepadWndProc();
  125. extern  HWND PASCAL DialogCreateIndirect(HWND hParent,int row1,int col1,int row2,int col2,BYTE *szTitle,WORD attr,DWORD fFlags,int (PASCAL *pfnDlgProc)(),struct dlgTemplate *pTemplate,int nTemplate);
  126. extern  int PASCAL ListboxDialogProc(HWND hDlg,WORD message,WORD wParam,DWORD lParam);
  127. extern  void TimerDemo(void );
  128. extern  WORD TimerMenuInit(void);
  129. extern  long PASCAL TimerWndProc(HWND hWnd,WORD msg,WORD wParam,LONG lParam);
  130. extern  void NewInterval(HWND hWnd);
  131. extern  int PASCAL IntervalDlgProc(HWND hDlg,WORD msg,WORD wParam,DWORD lParam);
  132. extern  int AreTimersRunning(void );
  133. extern  void KillAllTimers(void );
  134. extern  int MouseDemo(void );
  135. extern  int PrintScrollbarValues(WORD message,WORD wParam,LONG lParam);
  136. extern  void DoFloatingPopup(void );
  137. extern  void ComboDemo(void);
  138. extern  int PASCAL ComboDialogProc(HWND hDlg,WORD msg,WORD wParam,DWORD lParam);
  139. extern  int NotePad(void );
  140. extern  int NotepadOpenFile(BYTE *fname);
  141. extern  long PASCAL NotepadWndProc(HWND hWnd,WORD message,WORD wParam,LONG lParam);
  142. extern  void DOSEscape(void );
  143. extern  int Calculator(void );
  144. extern  void ShowNumber(HWND hWnd,DWORD dwNumber);
  145. extern  DWORD CalcIt(DWORD dwFirstNum,WORD nOperation,DWORD dwNum);
  146. extern  int PASCAL DlgProc(HWND hWnd,WORD iMessage,WORD wParam,DWORD lParam);
  147. extern  int BadCommand(void );
  148. extern  void ChildDemo(void );
  149. extern  long PASCAL PanelWndProc(HWND hWnd,WORD message,WORD wParam,LONG lParam);
  150. extern  void CreateChildren(HWND hParent);
  151. extern  void TerminateChildDemo(void );
  152. extern  void GraphicsModeDemo(void );
  153. extern  void VideoModeDemo(void );
  154. extern  long memavail(void );
  155.  
  156.  
  157. /*
  158.   Global Window Handles
  159. */
  160. HWND hMain;
  161. HWND hMsgWnd;
  162. HWND hWndTime;
  163. HWND hMouseWnd = NULLHWND;
  164. HWND hWndCalc = NULLHWND;
  165.  
  166. #ifdef MODELESSTEST
  167. HWND hWndListbox = NULLHWND;
  168. HWND hWndString;
  169. #endif
  170.  
  171.  
  172. HANDLE hInstance = 0;
  173.  
  174. main(int argc, char **argv)
  175. {
  176.   (void) argv;   (void) argc;
  177.  
  178.   /*
  179.     Initialize the window system - this *must* be done once in every appl
  180.   */
  181.   WinInit();
  182.   WinUseSysColors(NULLHWND, TRUE);
  183. //SET_PROGRAM_STATE(STATE_DEFER_VIRTSCREEN);
  184. #ifdef CTLCOLOR_TEST
  185.   SetWindowsCompatibility(WC_SEND_WMCTLCOLOR);
  186. #endif
  187.   bMessageBoxHasShadow = TRUE;
  188.  
  189. #if 0
  190. #if !defined(UNIX) && !defined(OS2) && !defined(VMS)
  191.   /*
  192.     If you want nice VGA fonts, make this call!
  193.   */
  194.   VidInitVGAFonts();
  195. #endif
  196. #endif
  197.  
  198.  
  199. #if defined(UNIX) || defined(OS2) || defined(VMS)
  200.   hInstance = OpenResourceFile("mewldemo");
  201. #endif
  202.  
  203.   return WinMain(hInstance, 0, NULL, SW_SHOW);
  204. }
  205.  
  206.  
  207. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  208.   HANDLE hInstance, hPrevInstance;
  209.   LPSTR  lpszCmdLine;
  210.   int    nCmdShow;
  211. {
  212.   MSG    msg;
  213.   HWND   hMenu, hPop;
  214.   WORD   hRes;
  215.   char   szBuf[64];
  216.   HACCEL hAccel;
  217.   static int iLastSec = -1;
  218.  
  219.  
  220.   (void) lpszCmdLine;
  221.  
  222.   /*
  223.     Register the main window class.
  224.   */
  225.   if (!hPrevInstance)
  226.     if (!InitApp(hInstance))
  227.       exit(1);
  228.  
  229.   /*
  230.     Create the main window and set the main window procedure
  231.   */
  232.   LoadString(hInstance, IDS_MAINTITLE, (LPSTR) szBuf, sizeof(szBuf));
  233.   hMain = CreateWindow("Mewldemo",            /* class */
  234.                        szBuf,                 /* title */
  235.                        WS_BORDER  |           /* dwStyle */ 
  236.                        WS_CLIP    |
  237.                        WS_SYSMENU | WS_CAPTION | WS_VSCROLL | WS_HSCROLL,
  238.                        CW_USEDEFAULT,0,       /* x,y,width,height */
  239.                        CW_USEDEFAULT,0,       /* x,y,width,height */
  240.                        NULLHWND,              /* hParent */
  241.                        NULLHWND,              /* hMenu */
  242.                        hInstance,             /* hInst */
  243.                        0L);                   /* lpParam */
  244.  
  245.   /*
  246.     Load in the accelerator table
  247.   */
  248.   hAccel = LoadAccelerators(hInstance, (LPSTR) "Mewldemo");
  249.  
  250.  
  251.   /*
  252.     Create a child window to display the output messages.
  253.   */
  254.   hMsgWnd =  CreateWindow("Normal",        /* class */
  255.                            NULL,           /* title */
  256.                            WS_CLIP,        /* dwStyle */
  257.                            1, GetSystemMetrics(SM_CYSCREEN) - 2,
  258.                            42, 1,
  259.                            hMain,          /* hParent */
  260.                            NULLHWND,       /* hMenu */
  261.                            hInstance,      /* hInst */
  262.                            0L);            /* lpParam */
  263.  
  264.   /*
  265.     Create a window for the clock
  266.   */
  267.   hWndTime = CreateWindow("Normal",  
  268.                           NULL,
  269.                           WS_CLIP, 
  270.                           45, GetSystemMetrics(SM_CYSCREEN) - 2,
  271.                           11, 1, 
  272.                           hMain,          /* hParent */
  273.                           NULLHWND,       /* hMenu */
  274.                           0,              /* hInst */
  275.                           0L);            /* lpParam */
  276.  
  277.   /*
  278.     Show the window
  279.   */
  280.   ShowWindow(hMain, nCmdShow);
  281.   UpdateWindow(hMain);
  282.  
  283.  
  284.   /*
  285.     Main message loop
  286.   */
  287.   for (;;)
  288.   {
  289.     /*
  290.       This is how you can do background processing
  291.     */
  292.     while (!PeekMessage(&msg, NULLHWND, 0, 0, PM_REMOVE))
  293.     {
  294.       int h, m, s;
  295.       char szTime[16];
  296.       DosGetTime(&h, &m, &s);
  297.       if (s != iLastSec)
  298.       {
  299.         sprintf(szTime, "%02d:%02d:%02d", h, m, s);
  300.         WinPuts(hWndTime, 0, 0, szTime, WinGetAttr(hWndTime));
  301.         iLastSec = s;
  302.       }
  303.     }
  304.     if (msg.message == WM_QUIT)
  305.       break;
  306.     if (msg.message == WM_MOUSEMOVE && hMouseWnd)
  307.     {
  308.       POINT pt;
  309.       pt = MAKEPOINT(msg.lParam);
  310.       sprintf(szBuf, "ROW [%2d]  COL [%2d]", pt.y, pt.x);
  311.       WinPutsCenter(hMouseWnd, 0, (PSTR) szBuf, 0x31);
  312.     }
  313.     if (hWndCalc && IsDialogMessage(hWndCalc, &msg))
  314.       continue;
  315. #ifdef MODELESSTEST
  316.     if (hWndListbox && IsDialogMessage(hWndListbox, &msg))
  317.       continue;
  318. #endif
  319.     if (!TranslateAccelerator(hMain, hAccel, &msg))
  320.     {
  321.       TranslateMessage(&msg);
  322.       DispatchMessage(&msg);
  323.     }
  324.   }
  325.  
  326.   return 0;
  327. }
  328.  
  329.  
  330. /****************************************************************************/
  331. /*                                                                          */
  332. /* Function : InitApp                                                       */
  333. /*                                                                          */
  334. /* Purpose  : Registers the window class                                    */
  335. /*                                                                          */
  336. /* Returns  :                                                               */
  337. /*                                                                          */
  338. /****************************************************************************/
  339. BOOL InitApp(hInstance)
  340.   HANDLE hInstance;
  341. {
  342.   HANDLE    hClass;
  343.   PWNDCLASS pClass;
  344.  
  345.   hClass = LocalAlloc(LPTR, sizeof(WNDCLASS));
  346.   pClass = (PWNDCLASS) LocalLock(hClass);
  347.  
  348.   pClass->hCursor       = LoadCursor(NULL, IDC_ARROW);
  349.   pClass->hIcon         = (HICON) NULL;
  350.   pClass->lpszMenuName  = "MainMenu";
  351.   pClass->lpszClassName = "Mewldemo";
  352.   pClass->hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  353.   pClass->hInstance     = hInstance;
  354.   pClass->style         = CS_HREDRAW | CS_VREDRAW;
  355.   pClass->lpfnWndProc   = MainWndProc;
  356.  
  357.   if (!RegisterClass((LPWNDCLASS) pClass))
  358.     /*
  359.      * Initialization failed. Windows will automatically deallocate all
  360.      * allocated memory. 
  361.      */
  362.     return FALSE;
  363.  
  364.   /*
  365.     Register the notepad class
  366.   */
  367.   pClass->lpszMenuName  = (LPSTR) "NotePad";
  368.   pClass->lpszClassName = "NotePad";
  369.   pClass->lpfnWndProc   = NotepadWndProc;
  370.   if (!RegisterClass((LPWNDCLASS) pClass))
  371.     return FALSE;
  372.  
  373.   LocalUnlock(hClass);
  374.   LocalFree(hClass);
  375.   return TRUE;            /* Initialization succeeded */
  376. }
  377.  
  378.  
  379.  
  380. /****************************************************************************/
  381. /*                                                                          */
  382. /* Function : MainWndProc                                                   */
  383. /*                                                                          */
  384. /* Purpose  : Window procedure for the main window.                         */
  385. /*                                                                          */
  386. /* Returns  :                                                               */
  387. /*                                                                          */
  388. /****************************************************************************/
  389. long PASCAL MainWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
  390. {
  391.   BYTE buf[80];
  392.  
  393.   switch (message)
  394.   {
  395.     case WM_COMMAND    :
  396.       /*
  397.         See if the user chose a demo from the DEMO menubar item
  398.       */
  399.       switch (wParam)
  400.       {
  401. #ifdef DOS
  402.         case IDM_MEMAVAIL :
  403.         {
  404.           char msg[80];
  405.           sprintf(msg, " Available memory is: %lu kB ", memavail() / 1024 );
  406.           MessageBox(hMain, msg, "Available memory", MB_OK);
  407.           break;
  408.         }
  409. #endif
  410.  
  411.         case ID_CALCDEMO :
  412.           Calculator();
  413.           break;
  414.  
  415.         case ID_LISTDEMO :
  416.           if (AreTimersRunning())
  417.             KillAllTimers();
  418. #ifdef MODELESSTEST
  419.           if ((hWndListbox = 
  420.                CreateDialog(hInstance,"ListDemoDlg",hMain,
  421.                             (FARPROC) ListboxDialogProc)) != NULL)
  422.           {
  423.             ShowWindow(hWndListbox, SW_SHOW);
  424.             SetFocus(hWndListbox);
  425.             hWndString = GetDlgItem(hWndListbox, ID_STRING);
  426.           }
  427. #else
  428.           DialogBox(hInstance, "ListDemoDlg", hMain, 
  429.                     (FARPROC) ListboxDialogProc);
  430. #endif
  431.           break;
  432.  
  433.         case ID_TIMEDEMO :
  434.           if (AreTimersRunning())
  435.             KillAllTimers();
  436.           TimerDemo();
  437.           break;
  438.  
  439.         case ID_MOUSEDEMO:
  440.           if (hMouseWnd)
  441.           {
  442.             DestroyWindow(hMouseWnd);
  443.             hMouseWnd = NULLHWND;
  444.             CheckMenuItem(GetMenu(hMain), ID_MOUSEDEMO, MF_UNCHECKED);
  445.           }
  446.           else
  447.           {
  448.             MouseDemo();
  449.             CheckMenuItem(GetMenu(hMain), ID_MOUSEDEMO, MF_CHECKED);
  450.           }
  451.           break;
  452.  
  453.         case ID_MENUDEMO:
  454.           DoFloatingPopup();
  455.           break;
  456.  
  457.         case ID_FILEDEMO :
  458.           /*
  459.             DlgOpenFile is an undocumented MEWEL call which displays a
  460.             standard file-open dialog box.
  461.           */
  462.           if (DlgOpenFile(NULLHWND, (PSTR) "*.*", buf))
  463.           {
  464.             char msg[80];
  465.             sprintf(msg, "You chose %s", buf);
  466.             MessageBox(hMain, buf, "Files Demo", MB_OK);
  467.           }
  468.           break;
  469.  
  470.         case ID_EDITDEMO :
  471.           NotePad();
  472.           break;
  473.  
  474.         case ID_EXECDEMO :
  475.           DOSEscape();
  476.           break;
  477.  
  478.         case ID_CHILDDEMO:
  479.           ChildDemo();
  480.           break;
  481.  
  482.         case ID_EXIT     :
  483.           PostQuitMessage(0);
  484.           break;
  485.  
  486.         case ID_COMBODEMO:
  487.           ComboDemo();
  488.           break;
  489.  
  490.         case ID_GRAPHICS :
  491.           GraphicsModeDemo();
  492.           break;
  493.  
  494.         case ID_TOGGLEEGA :
  495.           VideoModeDemo();
  496.           break;
  497.  
  498.  
  499.         case ID_WORD50 :
  500.           MessageBox(NULLHWND, (PSTR) "You chose Word 5.0", (PSTR) "WM_COMMAND", MB_OK);
  501.           break;
  502.         case ID_WRITE :
  503.           MessageBox(NULLHWND, (PSTR) "You chose WRITE", (PSTR) "WM_COMMAND", MB_OK);
  504.           break;
  505.         case ID_EXCEL :
  506.           MessageBox(NULLHWND, (PSTR) "You chose EXCEL", (PSTR) "WM_COMMAND", MB_OK);
  507.           break;
  508.         case ID_124   :
  509.           MessageBox(NULLHWND, (PSTR) "You chose 1+2=4", (PSTR) "WM_COMMAND", MB_OK);
  510.           break;
  511.         case ID_C52   :
  512.           MessageBox(NULLHWND, (PSTR) "You chose C 5.2", (PSTR) "WM_COMMAND", MB_OK);
  513.           break;
  514.         case ID_QUICKC :
  515.           MessageBox(NULLHWND, (PSTR) "You chose QUICK C", (PSTR) "WM_COMMAND", MB_OK);
  516.           break;
  517.         case ID_QUICKBASIC :
  518.           MessageBox(NULLHWND, (PSTR) "You chose QUICK BASIC", (PSTR) "WM_COMMAND", MB_OK);
  519.           break;
  520.         case ID_PASCAL  :
  521.           MessageBox(NULLHWND, (PSTR) "You chose PASCAL", (PSTR) "WM_COMMAND", MB_OK);
  522.           break;
  523.  
  524.         case ID_ABOUT   :
  525.           MessageBox(NULLHWND, (PSTR) "MEWEL Window System\nMagma Systems\n(201) 912-0192",
  526.                      (PSTR) "About MEWEL", MB_OK | MB_ICONASTERISK);
  527.           break;
  528.         case ID_HELP    :
  529.           goto do_help;
  530.       }
  531.       break;
  532.  
  533.  
  534.     case WM_CHAR       :
  535.       if (wParam == VK_CTRL_BREAK)
  536.         MessageBox(hMain, (PSTR) "You hit the CTRL+BREAK key", (PSTR) "Warning", MB_OK);
  537.       break;
  538.  
  539.  
  540.     case WM_VSCROLL :
  541.     case WM_HSCROLL :
  542.       PrintScrollbarValues(message, wParam, lParam);
  543.       break;
  544.  
  545.     case WM_HELP       :
  546. do_help:
  547.       MessageBox(hWnd,
  548. "MEWEL Demonstration Program\nMagma Systems\n15 Bodwell Terrace\nMillburn, NJ 07041\n\
  549. (201) 912-0192 (voice)\n(201) 912-0668 (BBS)\n(201) 912-0103 (FAX)",
  550.                  "MEWLDEMO", MB_OK | MB_ICONASTERISK);
  551.       break;
  552.  
  553.     case WM_MENUSELECT  :
  554.     {
  555.       WORD idMenu;
  556.       WORD iLen;
  557.  
  558.       /*
  559.         We trigger off of the WM_MENUSELECT message so that we
  560.         can print informative messages about each menu option.
  561.       */
  562.  
  563.       /*
  564.         An actual menu item identifier is returned in wParam...
  565.       */
  566.       idMenu = wParam;
  567.  
  568.       /*
  569.         If lParam was <-1,0>, then the user dismissed the menu, so
  570.         we just want to erase the previous help text from the
  571.         status window. If not, then idMenu contains a valid menu or
  572.         submenu identifier. Load the corresponding string from
  573.         the string table, and print it.
  574.       */
  575.       if (LOWORD(lParam) == 0 && HIWORD(lParam) == 0  ||
  576.          LoadString(hInstance, idMenu, (LPSTR) buf, sizeof(buf)) > 0)
  577.       {
  578.         WinClear(hMsgWnd);
  579.         if (LOWORD(lParam) == 0 && HIWORD(lParam) == 0)
  580.           ;
  581.         else
  582.           WinPuts(hMsgWnd, 0, 0, buf, WinGetAttr(hMsgWnd));
  583.       }
  584.       else
  585.         WinClear(hMsgWnd);
  586.       break;
  587.     }
  588.  
  589.  
  590. #ifdef MODELESSTEST
  591.     case WM_INITMENUPOPUP :
  592.       if (hWndListbox && hWndString)
  593.       {
  594.         DWORD iSel = SendMessage(hWndString, EM_GETSEL, 0, 0L);
  595.         if (iSel)
  596.           iSel++;  // dummy
  597.       }
  598.       break;
  599. #endif
  600.  
  601.  
  602.     case WM_DEVMODECHANGE :
  603.       /*
  604.         Probably toggled between 25 and 43/50 line modes
  605.       */
  606.       WinSetSize(hWnd,GetSystemMetrics(SM_CYSCREEN),GetSystemMetrics(SM_CXSCREEN));
  607.       WinMove(hMsgWnd,GetSystemMetrics(SM_CYSCREEN) - 2, 1);
  608.       WinMove(hWndTime,GetSystemMetrics(SM_CYSCREEN) - 2,45);
  609.       break;
  610.  
  611.  
  612.     default :
  613.       /* Call the default window procedure for the main window */
  614.       return DefWindowProc(hWnd, message, wParam, lParam);
  615.   }
  616.  
  617.   return FALSE;
  618. }
  619.  
  620.  
  621. /****************************************************************************/
  622. /*                                                                          */
  623. /* Function : DialogCreateIndirect()                                        */
  624. /*                                                                          */
  625. /* Purpose  : A function you can use to build dialog boxes on-the-fly.      */
  626. /*                                                                          */
  627. /* Returns  : The handle of the created dialog box                          */
  628. /*                                                                          */
  629. /****************************************************************************/
  630. HWND PASCAL DialogCreateIndirect(HWND hParent, 
  631.                                  int row1, int col1, int row2, int col2,
  632.                                  BYTE *szTitle,
  633.                                  WORD attr, DWORD fFlags, 
  634.                                  int (PASCAL *pfnDlgProc)(),
  635.                                  DTEMPLATE *pTemplate, int nTemplate)
  636. {
  637.   HDLG hDlg;
  638.   HWND hCtrl;
  639.  
  640.   hDlg = DialogCreate(hParent,row1,col1,row2,col2,szTitle,attr,fFlags,pfnDlgProc,0,NULL);
  641.   if (hDlg == NULLHWND)
  642.     return NULLHWND;
  643.  
  644.   while (nTemplate-- > 0)
  645.   {
  646.     hCtrl = _CreateWindow(pTemplate->szClass, pTemplate->szTitle,
  647.                          pTemplate->dwStyle,
  648.                          pTemplate->x,     pTemplate->y,
  649.                          pTemplate->width, pTemplate->height,
  650.                          0x31, pTemplate->idCtrl,
  651.                          hDlg,              /* hParent */
  652.                          (HMENU) NULLHWND,  /* hMenu   */
  653.                          0,                 /* hInst   */
  654.                          (DWORD) NULL);     /* lpCreateParams */
  655.     if (hCtrl == NULLHWND)
  656.       return NULLHWND;
  657.     pTemplate++;
  658.   }
  659.  
  660.   return (HWND) hDlg;
  661. }
  662.  
  663.  
  664.  
  665. /****************************************************************************/
  666. /*                                                                          */
  667. /* Function : ListDemo()                                                    */
  668. /*                                                                          */
  669. /* Purpose  : Code to implement the listbox demo                            */
  670. /*                                                                          */
  671. /* Returns  :                                                               */
  672. /*                                                                          */
  673. /****************************************************************************/
  674. int PASCAL ListboxDialogProc(HWND hDlg, WORD message, WORD wParam, DWORD lParam)
  675. {
  676.   BYTE szString[130];
  677.   BYTE szPos[30];
  678.   int  iPos;
  679.   int  operation;
  680.   int  iSel;
  681.   static BYTE szItemText[130];
  682.   static int  nMovedItem = - 1;
  683.  
  684. #ifdef MODELESSTEST
  685.   static HBRUSH hBlueBrush = 0;
  686. #endif
  687.  
  688.   switch (message)
  689.   {
  690.     case WM_INITDIALOG :
  691.       SendDlgItemMessage(hDlg, ID_STRING, EM_SETSEL, 0, (DWORD) 0x7FFF);
  692.       SendDlgItemMessage(hDlg, ID_POS,    EM_SETSEL, 0, (DWORD) 0x7FFF);
  693.       CheckRadioButton(hDlg, ID_APPEND, ID_DELETE, ID_APPEND);
  694. #ifdef MODELESSTEST
  695.       if (!hBlueBrush)
  696.       {
  697.         hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
  698.         SetWindowsCompatibility(WC_SEND_WMCTLCOLOR);
  699.       }
  700. #endif
  701.       return TRUE;
  702.  
  703.     case WM_CHAR :
  704.       if (wParam == VK_ALT_M && GetDlgItem(hDlg, ID_LISTBOX) == GetFocus())
  705.       {
  706.         if (nMovedItem < 0)
  707.         {
  708.           nMovedItem = (int) SendDlgItemMessage(hDlg,ID_LISTBOX,LB_GETCURSEL,0,0L);
  709.           SendDlgItemMessage(hDlg, ID_LISTBOX, LB_GETTEXT,
  710.                              nMovedItem, (DWORD) (BYTE far *) szItemText);
  711.         }
  712.         else
  713.           nMovedItem = -1;
  714.         return TRUE;
  715.       }
  716.  
  717.       if (wParam == VK_ALT_K && GetDlgItem(hDlg, ID_LISTBOX) == GetFocus())
  718.       {
  719.         SendDlgItemMessage(hDlg, ID_LISTBOX, LB_RESETCONTENT, 0, 0L);
  720.       }
  721.       break;
  722.  
  723.     case WM_VALIDATE   :
  724.       if (wParam == ID_POS)
  725.       {
  726.         GetDlgItemText(hDlg, ID_POS, (LPSTR) szString, sizeof(szString));
  727.         if (!isdigit(szString[0]) && szString[0] != '\0')
  728.           return -1;
  729.       }
  730.       return TRUE;
  731.  
  732.     case WM_COMMAND    :
  733.       switch (wParam)
  734.       {
  735.           case IDOK      :
  736.           /*
  737.             The user pressed the OK button. We want to get the string
  738.             that is to be inserted as well as the position.
  739.           */
  740.           GetDlgItemText(hDlg, ID_STRING, (LPSTR) szString, sizeof(szString));
  741.           iPos = GetDlgItemInt(hDlg, ID_POS, NULL, TRUE);
  742.  
  743.           /*
  744.             Determine the operation to perform
  745.           */
  746.           operation = 0;
  747.           if (IsDlgButtonChecked(hDlg, ID_APPEND))
  748.             operation = LB_ADDSTRING;
  749.           else if (IsDlgButtonChecked(hDlg, ID_INSERT))
  750.             operation = LB_INSERTSTRING;
  751.           else if (IsDlgButtonChecked(hDlg, ID_DELETE))
  752.             operation = LB_DELETESTRING;
  753.  
  754.           if (operation)
  755.           {
  756.             SendDlgItemMessage(hDlg, ID_LISTBOX, operation, iPos,
  757.                                       (DWORD) (BYTE far *) szString);
  758.             MessageBox(NULLHWND, szString, (PSTR) "Completed", MB_OK | MB_ICONEXCLAMATION);
  759.           }
  760.           break;
  761.  
  762.         case IDCANCEL  :
  763.           /*
  764.              If the user pressed the QUIT button, then send a WM_QUIT
  765.              message to all the window procs
  766.           */
  767.           EndDialog(hDlg, 0);
  768.           break;
  769.  
  770.         case ID_LISTBOX :
  771.           switch (HIWORD(lParam))
  772.           {
  773.             case LBN_SELCHANGE :
  774.               if (nMovedItem < 0)
  775.                 return FALSE;
  776.               iSel = (int) SendDlgItemMessage(hDlg,ID_LISTBOX,LB_GETCURSEL,0,0L);
  777.               SendDlgItemMessage(hDlg,ID_LISTBOX,LB_DELETESTRING,nMovedItem,0L);
  778.               SendDlgItemMessage(hDlg,ID_LISTBOX,LB_INSERTSTRING,iSel,
  779.                                  (DWORD) (BYTE far *) szItemText);
  780.               nMovedItem = iSel;
  781.               break;
  782.           }
  783.           return FALSE;
  784.  
  785.         case ID_POS :
  786.           if (HIWORD(lParam) == FN_ERRVALIDATE)
  787.           {
  788.             MessageBox(hDlg, (PSTR) "Bad format for position", 
  789.                        (PSTR) "Format Error", MB_OK | MB_ICONHAND);
  790.           }
  791.           break;
  792.       }
  793.  
  794.       return TRUE;
  795.  
  796. #ifdef MODELESSTEST
  797.     case WM_SETFOCUS :
  798.       SetFocus(GetDlgItem(hDlg, ID_STRING));
  799.       return TRUE;
  800.  
  801.     case WM_CTLCOLOR :
  802.     if (HIWORD(lParam) == CTLCOLOR_EDIT)
  803.     {
  804.       HBRUSH hBrush = hBlueBrush;
  805.       SetTextColor(wParam, RGB(0, 255, 255));   // cyan fore
  806.       SetBkColor(wParam, RGB(0, 0, 255));  // blue background
  807.       return hBrush;
  808.     }
  809.     else
  810.       return GetStockObject(WHITE_BRUSH);
  811.  
  812.  
  813.     case WM_CLOSE :
  814.       hWndListbox = NULLHWND;
  815.       DestroyWindow(hDlg);
  816.       return TRUE;
  817. #endif
  818.  
  819.   }
  820.  
  821.   return FALSE;
  822. }
  823.  
  824.  
  825. /**************************************************************************/
  826. /*                                                                        */
  827. /*             TIMER DEMO                                                 */
  828. /*                                                                        */
  829. /**************************************************************************/
  830. #define NUMTIMERS  8
  831. HWND hTimerWnd[NUMTIMERS];
  832.  
  833. extern long PASCAL TimerWndProc(HWND, WORD, WORD, LONG);
  834.  
  835.  
  836. VOID TimerDemo(VOID)
  837. {
  838.   int   i;
  839.   HWND  hWnd;
  840.   HMENU hMenu;
  841.   char  title[16];
  842.  
  843.   MessageBox(hMain,
  844. (PSTR) "The timer strings will occasionally overwrite the child windows.\nTHIS IS NOT A BUG.",
  845.              (PSTR) "Heed this", MB_OK | MB_ICONEXCLAMATION);
  846.  
  847.   for (i = 1;  i <= NUMTIMERS;  i++)
  848.   {
  849.     sprintf(title, "Timer %d", i);
  850.  
  851.     hWnd = hTimerWnd[i-1] =
  852.        CreateWindow((PSTR) "Normal",       /* class */
  853.                     (PSTR) title,          /* title */
  854.                     WS_BORDER | WS_CLIP, /* dwStyle */
  855.                     ((i-1)%2) ? 40 : 20, 
  856.                     ((i-1)/2)*5 + 3,
  857.                     25, 4,
  858.                     hMain,          /* hParent */
  859.                     NULLHWND,       /* hMenu */
  860.                     0,              /* hInst */
  861.                     0L);            /* lpParam */
  862.  
  863.     WinSetWinProc(hWnd, TimerWndProc);
  864.     hMenu = TimerMenuInit();
  865.     SetMenu(hWnd, hMenu);
  866.     SetTimer(hWnd, i, i*1000, (FARPROC) NULL);
  867.   }
  868.  
  869.   ShowWindow(hMain, TRUE);
  870.   SetFocus(hTimerWnd[0]);
  871. }
  872.  
  873.  
  874. HMENU TimerMenuInit()
  875. {
  876.   HMENU hMenu, hPop;
  877.  
  878.   /*
  879.     Create the menu bar
  880.   */
  881.   hMenu = CreateMenu();
  882.   
  883.   /*
  884.     Create a pulldown
  885.   */
  886.   hPop = CreateMenu();
  887.   ChangeMenu(hPop, 0, (PSTR) "~Stop",        ID_STOP,        MF_APPEND);
  888.   ChangeMenu(hPop, 0, (PSTR) "~Interval",    ID_INTERVAL,    MF_APPEND);
  889.   ChangeMenu(hPop, 0, (PSTR) "E~xit",        ID_EXIT,        MF_APPEND);
  890.  
  891.   /*
  892.     Attach each of the pulldowns to their corresponding menubar entries
  893.   */
  894.   ChangeMenu(hMenu, 0, (PSTR) "~Timer",   hPop, MF_POPUP | MF_APPEND);
  895.  
  896.   return hMenu;
  897. }
  898.  
  899.  
  900. long PASCAL TimerWndProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam)
  901. {
  902.   char szTime[80];
  903.   int  hrs, min, sec;
  904.   int  i;
  905.   extern VOID FAR PASCAL SoundNote(int,int,unsigned);
  906.  
  907.   switch (msg)
  908.   {
  909.     case WM_TIMER :
  910.       DosGetTime(&hrs, &min, &sec);
  911.       sprintf(szTime, "%02d:%02d:%02d", hrs, min, sec);
  912.       WinPutsCenter(hWnd, 0, (PSTR) szTime, WinGetAttr(hWnd));
  913.       SoundNote(CNOTE + wParam, MIN_OCTAVE + wParam, 100);
  914.       return TRUE;
  915.  
  916.     case WM_CHAR    :
  917.       if (wParam == VK_TAB)
  918.       {
  919.         for (i = 1;  i <= NUMTIMERS;  i++)
  920.           if (hTimerWnd[i-1] == hWnd)
  921.           {
  922.             SetFocus(hTimerWnd[ (i == NUMTIMERS) ? 0 : i ]);
  923.             return TRUE;
  924.           }
  925.       }
  926.       break;
  927.  
  928.     case WM_SETFOCUS :
  929.       BringWindowToTop(hWnd);
  930.       return DefWindowProc(hWnd, msg, wParam, lParam);
  931.  
  932.     case WM_COMMAND :
  933.       switch (wParam)
  934.       {
  935.         case ID_EXIT :
  936.         case ID_STOP :
  937.           for (i = 1;  i <= NUMTIMERS;  i++)
  938.             if (hTimerWnd[i-1] == hWnd)
  939.             {
  940.               KillTimer(hWnd, i);
  941.               ChangeMenu(GetSubMenu(GetMenu(hWnd), 0),
  942.                          0, (PSTR) "Start", ID_START, MF_CHANGE | MF_STRING);
  943.             }
  944.  
  945.           if (wParam == ID_EXIT)
  946.           {
  947.             /*
  948.               Setting focus to a non-timer window will eliminate the
  949.               situation where DestroyWindow(), detecting that the
  950.               window with the focus is being destroyed, sets the focus
  951.               to the next timer window (which will only be destroyed
  952.               in the next interation of the for loop). This will speed
  953.               up the process of destruction.
  954.             */
  955.             SetFocus(hMain);
  956.             for (i = 1;  i <= NUMTIMERS;  i++)
  957.             {
  958.               DestroyWindow(hTimerWnd[i-1]);
  959.               hTimerWnd[i-1] = NULLHWND;
  960.             }
  961.           }
  962.           break;
  963.  
  964.         case ID_START:
  965.           for (i = 1;  i <= NUMTIMERS;  i++)
  966.             if (hTimerWnd[i-1] == hWnd)
  967.             {
  968.               SetTimer(hWnd, i, i*1000, (FARPROC) NULL);
  969.               ChangeMenu(GetSubMenu(GetMenu(hWnd), 0),
  970.                          0, (PSTR) "Stop", ID_STOP, MF_CHANGE | MF_STRING);
  971.             }
  972.           break;
  973.  
  974.         case ID_INTERVAL :
  975.           NewInterval(hWnd);
  976.           break;
  977.       }
  978.       return TRUE;
  979.  
  980.     default :
  981.       return DefWindowProc(hWnd, msg, wParam, lParam);
  982.   }
  983.   return TRUE;
  984. }
  985.  
  986.  
  987. VOID NewInterval(HWND hWnd)
  988. {
  989.   HDLG hDlg;
  990.   int  i, tid;
  991.   unsigned interval;
  992.   extern int  PASCAL IntervalDlgProc();
  993.  
  994.   for (i = 1;  i <= NUMTIMERS;  i++)
  995.     if (hTimerWnd[i-1] == hWnd)
  996.     {
  997.       tid = i;
  998.       break;
  999.     }
  1000.  
  1001.   hDlg = DialogCreateIndirect(NULLHWND,
  1002.                               8,26,13,51,
  1003.                               (PSTR) "New Interval",
  1004.                               0x31,0L,IntervalDlgProc,
  1005.                               IntervalDialogTemplate,
  1006.                               sizeof(IntervalDialogTemplate) / sizeof(DTEMPLATE));
  1007.  
  1008.   if ((interval = _DialogBox(hDlg)) != IDCANCEL)
  1009.   {
  1010.     KillTimer(hWnd, tid);
  1011.     SetTimer(hWnd, tid, interval, (FARPROC) NULL);
  1012.   }
  1013. }
  1014.  
  1015.  
  1016. int PASCAL IntervalDlgProc(HWND hDlg, WORD msg, WORD wParam, DWORD lParam)
  1017. {
  1018.   char szInterval[80];
  1019.  
  1020.   (void) lParam;
  1021.  
  1022.   switch (msg)
  1023.   {
  1024.     case WM_INITDIALOG :
  1025.       return TRUE;
  1026.  
  1027.     case WM_COMMAND :
  1028.       if (wParam == IDCANCEL)
  1029.         EndDialog(hDlg, IDCANCEL);
  1030.       else if (wParam == IDOK)
  1031.       {
  1032.         GetDlgItemText(hDlg, ID_INTERVAL, (BYTE far *) szInterval, 65);
  1033.         EndDialog(hDlg, atoi(szInterval));
  1034.       }
  1035.       return TRUE;
  1036.  
  1037.     default :
  1038.       return FALSE;
  1039.   }
  1040. }
  1041.  
  1042. int AreTimersRunning(VOID)
  1043. {
  1044.   return hTimerWnd[0];
  1045. }
  1046.  
  1047. VOID KillAllTimers(VOID)
  1048. {
  1049.   SendMessage(hTimerWnd[0], WM_COMMAND, ID_EXIT, 0L);
  1050. }
  1051.  
  1052.  
  1053. /**************************************************************************/
  1054. /*                                                                        */
  1055. /*             MOUSE DEMO                                                 */
  1056. /*                                                                        */
  1057. /**************************************************************************/
  1058. int MouseDemo(VOID)
  1059. {
  1060. #ifndef UNIX
  1061.   if (!GetSystemMetrics(SM_MOUSEPRESENT))
  1062.   {
  1063.     MessageBox(NULLHWND, (PSTR) "You must have a mouse to run this demo.",
  1064.                          (PSTR) "Error",MB_OK);
  1065.     return FALSE;
  1066.   }
  1067.  
  1068.   hMouseWnd = _CreateWindow((PSTR) "Normal",   /* class */
  1069.                        (PSTR) "Mouse Coordinates", /* title */
  1070.                        WS_BORDER | WS_CLIP,      /* dwStyle */
  1071.                        30,10, 20,3,    /* x,y,width,height */
  1072.                        0x31,           /* attr */
  1073.                        1,              /* id */
  1074.                        hMain,          /* hParent */
  1075.                        NULLHWND,       /* hMenu */
  1076.                        0,              /* hInst */
  1077.                        0L);            /* lpParam */
  1078.  
  1079.   ShowWindow(hMain, TRUE);
  1080.   return TRUE;
  1081. #endif
  1082. }
  1083.  
  1084.  
  1085. /**************************************************************************/
  1086. /*                                                                        */
  1087. /*  POPTEST.C - demonstration of the usage of floating popups             */
  1088. /*                                                                        */
  1089. /**************************************************************************/
  1090. VOID DoFloatingPopup(VOID)
  1091. {
  1092.   HMENU hMenu;
  1093.  
  1094.   if ((hMenu = LoadPopupMenu(hInstance, (LPSTR) "FloatingPopup")) != NULL)
  1095.     TrackPopupMenu(hMenu, 0,30,10,20, hMain, (LPRECT) NULL);
  1096. }
  1097.  
  1098.  
  1099. /*===========================================================================*/
  1100. /*                                                                           */
  1101. /* File    :  MOVETEST.C                                                     */
  1102. /*                                                                           */
  1103. /* Purpose :  Demo of child windows. Included moving, resizing, and clipping */
  1104. /*                                                                           */
  1105. /* History :                                                                 */
  1106. /*                                                                           */
  1107. /* (C) Copyright 1989 Marc Adler/Magma Systems     All Rights Reserved       */
  1108. /*===========================================================================*/
  1109. extern long PASCAL PanelWndProc();
  1110. HWND hPanel1, hPanel2, hPanel3;
  1111.  
  1112. static PSTR pszChildMsg = (PSTR) 
  1113. "You can move (drag the caption) or resize (drag lower-right corner)\n\
  1114. any of the 3 child windows.\n You can press the arrow keys to scroll\n\
  1115. the panels. This also demonstrates MEWEL clipping sibling windows.";
  1116.  
  1117.  
  1118. VOID ChildDemo(VOID)
  1119. {
  1120.   HANDLE hMemory;
  1121.   PWNDCLASS pWndClass;
  1122.  
  1123.   TerminateChildDemo();
  1124.   MessageBox(hMain, pszChildMsg, (PSTR) "Child Demo", MB_OK);
  1125.  
  1126.   hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS));
  1127.   pWndClass = (PWNDCLASS) LocalLock(hMemory);
  1128.   pWndClass->hCursor       = LoadCursor(NULL, IDC_ARROW);
  1129.   pWndClass->hIcon         = LoadIcon(NULLHWND, IDI_APPLICATION);
  1130.   pWndClass->lpszMenuName  = NULL;
  1131.   pWndClass->lpszClassName = "Panel";
  1132.   pWndClass->lpfnWndProc   = (WINPROC *) PanelWndProc;
  1133.  
  1134.   RegisterClass(pWndClass);
  1135.  
  1136.   LocalUnlock(hMemory);
  1137.   LocalFree(hMemory);
  1138.  
  1139.  
  1140.   hPanel1=_CreateWindow((PSTR) "Panel",        /* class */
  1141.                        (PSTR) "Panel1",       /* title */
  1142.                        WIN_HAS_BORDER | WIN_HAS_SHADOW | SHADOW_BOTRIGHT |
  1143.                        WIN_SYSMENU    | WIN_TITLEBAR | WIN_MINMAXBOX |
  1144.                        WIN_VSCROLL    | WIN_HSCROLL | WIN_MOVEBOX | WIN_SIZEBOX |
  1145.                        WS_CLIP,
  1146.                        4,3, 30,14,     /* x,y,width,height */
  1147.                        MAKE_ATTR(WHITE, RED),
  1148.                        1,              /* id */
  1149.                        hMain,          /* hParent */
  1150.                        NULLHWND,       /* hMenu */
  1151.                        0,              /* hInst */
  1152.                        0L);            /* lpParam */
  1153.   CreateChildren(hPanel1);
  1154.  
  1155.   hPanel2= _CreateWindow((PSTR) "Panel",       /* class */
  1156.                        (PSTR) "Panel2",       /* title */
  1157.                        WIN_HAS_BORDER | WIN_HAS_SHADOW | SHADOW_BOTRIGHT |
  1158.                        WIN_SYSMENU    | WIN_TITLEBAR | WIN_MINMAXBOX |
  1159.                        WIN_VSCROLL    | WIN_HSCROLL | WIN_MOVEBOX | WIN_SIZEBOX |
  1160.                        WS_CLIP,
  1161.                        24,6, 30,14,    /* x,y,width,height */
  1162.                        MAKE_ATTR(WHITE, BLUE),
  1163.                        2,              /* id */
  1164.                        hMain,          /* hParent */
  1165.                        NULLHWND,       /* hMenu */
  1166.                        0,              /* hInst */
  1167.                        0L);            /* lpParam */
  1168.   CreateChildren(hPanel2);
  1169.  
  1170.   hPanel3= _CreateWindow((PSTR) "Panel",       /* class */
  1171.                        (PSTR) "Panel3",       /* title */
  1172.                        WIN_HAS_BORDER | WIN_HAS_SHADOW | SHADOW_BOTRIGHT |
  1173.                        WIN_SYSMENU    | WIN_TITLEBAR | WIN_MINMAXBOX |
  1174.                        WIN_VSCROLL    | WIN_HSCROLL | WIN_MOVEBOX | WIN_SIZEBOX |
  1175.                        WS_CLIP,
  1176.                        44,9, 30,14,    /* x,y,width,height */
  1177.                        MAKE_ATTR(WHITE, BLACK),
  1178.                        2,              /* id */
  1179.                        hMain,          /* hParent */
  1180.                        NULLHWND,       /* hMenu */
  1181.                        0,              /* hInst */
  1182.                        0L);            /* lpParam */
  1183.   CreateChildren(hPanel3);
  1184.  
  1185.   /*
  1186.     Show the window
  1187.   */
  1188.   ShowWindow(hMain, TRUE);
  1189.   BringWindowToTop(hPanel1);
  1190.   SetFocus(hPanel1);
  1191.   CheckMenuItem(GetMenu(hMain), ID_CHILDDEMO, MF_CHECKED);
  1192. }
  1193.  
  1194.  
  1195. long PASCAL PanelWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
  1196. {
  1197.   switch (message)
  1198.   {
  1199.     case WM_MOUSEACTIVATE :
  1200.       BringWindowToTop(hWnd);
  1201.       return MA_ACTIVATEANDEAT;
  1202.  
  1203.     case WM_CHAR          :
  1204.       switch (wParam)
  1205.       {
  1206.         case VK_DOWN:
  1207.           ScrollWindow(hWnd, 0,  1,  (LPRECT) NULL, (LPRECT) NULL);
  1208.           break;
  1209.         case VK_UP  :
  1210.           ScrollWindow(hWnd, 0, -1,  (LPRECT) NULL, (LPRECT) NULL);
  1211.           break;
  1212.         case VK_LEFT:
  1213.           ScrollWindow(hWnd, -1, 0,  (LPRECT) NULL, (LPRECT) NULL);
  1214.           break;
  1215.         case VK_RIGHT:
  1216.           ScrollWindow(hWnd, 1, 0,   (LPRECT) NULL, (LPRECT) NULL);
  1217.           break;
  1218.         case VK_HOME:
  1219.           ScrollWindow(hWnd, -1, -1, (LPRECT) NULL, (LPRECT) NULL);
  1220.           break;
  1221.         case VK_PGUP:
  1222.           ScrollWindow(hWnd,  1, -1, (LPRECT) NULL, (LPRECT) NULL);
  1223.           break;
  1224.         case VK_END :
  1225.           ScrollWindow(hWnd, -1,  1, (LPRECT) NULL, (LPRECT) NULL);
  1226.           break;
  1227.         case VK_PGDN:
  1228.           ScrollWindow(hWnd,  1,  1, (LPRECT) NULL, (LPRECT) NULL);
  1229.           break;
  1230.       }
  1231.       return TRUE;
  1232.  
  1233.     case WM_CLOSE :
  1234.       DestroyWindow(hWnd);
  1235.       if (hWnd == hPanel1)
  1236.         hPanel1 = NULLHWND;
  1237.       else
  1238.       if (hWnd == hPanel2)
  1239.         hPanel2 = NULLHWND;
  1240.       else
  1241.       if (hWnd == hPanel3)
  1242.         hPanel3 = NULLHWND;
  1243.       if (!hPanel1 && !hPanel2 && !hPanel3)
  1244.         CheckMenuItem(GetMenu(hMain), ID_CHILDDEMO, MF_UNCHECKED);
  1245.       break;
  1246.  
  1247.     default :
  1248.       /* Call the default window procedure for the main window */
  1249.       return DefWindowProc(hWnd, message, wParam, lParam);
  1250.   }
  1251.  
  1252.   return FALSE;
  1253. }
  1254.  
  1255.  
  1256. struct childinfo
  1257. {
  1258.   char *szClass;
  1259.   char *szTitle;
  1260.   int  x, y, cx, cy;
  1261.   int  id;
  1262. } ChildInfo[] =
  1263. {
  1264.   { "Text",  "Business1:",1, 0,15,1, 24 } ,
  1265.   { "Edit",  NULL,       20, 0,45,1, 25 },
  1266.   { "Text",  "Business2:",1, 2,15,1, 24 } ,
  1267.   { "Edit",  NULL,       20, 2,45,1, 25 },
  1268.   { "Text",  "Business3", 1, 4,15,1, 24 } ,
  1269.   { "Edit",  NULL,       20, 4,45,1, 25 },
  1270.   { "Text",  "Business4", 1, 6,15,1, 24 } ,
  1271.   { "Edit",  NULL,       20, 6,45,1, 25 } ,
  1272.   { "Text",  "Business5", 1, 8,15,1, 24 } ,
  1273.   { "Edit",  NULL,       20, 8,45,1, 25 },
  1274. /*
  1275.   { "Text",  "Business6", 1,10,15,1, 24 } ,
  1276.   { "Edit",  NULL,       20,10,45,1, 25 },
  1277.   { "Text",  "Business7", 1,12,15,1, 24 } ,
  1278.   { "Edit",  NULL,       20,12,45,1, 25 },
  1279.   { "Text",  "Business8", 1,14,15,1, 24 } ,
  1280.   { "Edit",  NULL,       20,14,45,1, 25 },
  1281.   { "Text",  "Business9", 1,16,15,1, 24 } ,
  1282.   { "Edit",  NULL,       20,16,45,1, 25 },
  1283.   { "Text",  "Business0", 1,18,15,1, 24 } ,
  1284.   { "Edit",  NULL,       20,18,45,1, 25 },
  1285.   { "Text",  "BusinessA", 1,20,15,1, 24 } ,
  1286.   { "Edit",  NULL,       20,20,45,1, 25 },
  1287.   { "Text",  "BusinessB", 1,21,15,1, 24 } ,
  1288.   { "Edit",  NULL,       20,21,45,1, 25 },
  1289.   { "Text",  "BusinessC", 1,22,15,1, 24 } ,
  1290.   { "Edit",  NULL,       20,22,45,1, 25 },
  1291.   { "Text",  "BusinessD", 1,23,15,1, 24 } ,
  1292.   { "Edit",  NULL,       20,23,45,1, 25 },
  1293.   { "Text",  "BusinessE", 1,24,15,1, 24 } ,
  1294.   { "Edit",  NULL,       20,24,45,1, 25 },
  1295.   { "Text",  "BusinessF", 1,25,15,1, 24 } ,
  1296.   { "Edit",  NULL,       20,25,45,1, 25 },
  1297.   { "Text",  "BusinessG", 1,26,15,1, 24 } ,
  1298.   { "Edit",  NULL,       20,26,45,1, 25 },
  1299.   { "Text",  "BusinessH", 1,27,15,1, 24 } ,
  1300.   { "Edit",  NULL,       20,27,45,1, 25 },
  1301.   { "Text",  "BusinessI", 1,28,15,1, 24 } ,
  1302.   { "Edit",  NULL,       20,28,45,1, 25 },
  1303.   { "Text",  "BusinessJ", 1,29,15,1, 24 } ,
  1304.   { "Edit",  NULL,       20,29,45,1, 25 },
  1305.   { "Text",  "BusinessK", 1,30,15,1, 24 } ,
  1306.   { "Edit",  NULL,       20,30,45,1, 25 },
  1307.   { "Text",  "BusinessL", 1,31,15,1, 24 } ,
  1308.   { "Edit",  NULL,       20,31,45,1, 25 },
  1309.   { "Text",  "BusinessM", 1,32,15,1, 24 } ,
  1310.   { "Edit",  NULL,       20,32,45,1, 25 },
  1311. */
  1312. };
  1313.  
  1314.  
  1315. VOID CreateChildren(HWND hParent)
  1316. {
  1317.   struct childinfo *pCI;
  1318.   int    i;
  1319.   DWORD dwStyle = WS_CLIP;
  1320.   RECT  r;
  1321.   WORD  attr;
  1322.  
  1323.   r = WinGetClient(hParent);
  1324.   attr = WinGetAttr(hParent);
  1325.  
  1326.   for (i = 0;  i < sizeof(ChildInfo)/sizeof(ChildInfo[0]);  i++)
  1327.   {
  1328.     pCI = &ChildInfo[i];
  1329.     if (i & 0x01)
  1330.       dwStyle |= WS_BORDER;
  1331.     else
  1332.       dwStyle &= ~WS_BORDER;
  1333.  
  1334.     _CreateWindow((PSTR) pCI->szClass, (PSTR) pCI->szTitle, 
  1335.                        dwStyle,
  1336.                        pCI->x+r.left, pCI->y+r.top, pCI->cx, pCI->cy,
  1337.                        attr,           /* attr */
  1338.                        pCI->id,        /* id */
  1339.                        hParent,        /* hParent */
  1340.                        NULLHWND,       /* hMenu */
  1341.                        0,              /* hInst */
  1342.                        0L);            /* lpParam */
  1343.   }
  1344.  
  1345.   _CreateWindow((PSTR) "PushButton", (PSTR) "Push Me!", 
  1346.                WS_BORDER,
  1347.                1+r.left, r.bottom-2, 12, 3,
  1348.                attr,           /* attr */
  1349.                100,            /* id */
  1350.                hParent,        /* hParent */
  1351.                NULLHWND,       /* hMenu */
  1352.                0,              /* hInst */
  1353.                0L);            /* lpParam */
  1354.  
  1355. }
  1356.  
  1357.  
  1358. VOID TerminateChildDemo(VOID)
  1359. {
  1360.   if (hPanel1)
  1361.     SendMessage(hPanel1, WM_CLOSE, 0, 0L);
  1362.   if (hPanel2)
  1363.     SendMessage(hPanel2, WM_CLOSE, 0, 0L);
  1364.   if (hPanel3)
  1365.     SendMessage(hPanel3, WM_CLOSE, 0, 0L);
  1366.   CheckMenuItem(GetMenu(hMain), ID_CHILDDEMO, MF_UNCHECKED);
  1367. }
  1368.  
  1369.  
  1370.  
  1371. /*===========================================================================*/
  1372. /*                                                                           */
  1373. /* File    : NOTEPAD.C                                                       */
  1374. /*                                                                           */
  1375. /* Purpose : Demo of a multi-line edit field plus a new kind of button       */
  1376. /*                                                                           */
  1377. /*===========================================================================*/
  1378. #define MAXBUFSIZE  0xF000
  1379.  
  1380. static HWND hWndNotepad, hEdit;
  1381. static LPSTR pszFileToOpen = NULL;
  1382.  
  1383. int NotePad(VOID)
  1384. {
  1385.   if (hWndNotepad)
  1386.   {
  1387.     BringWindowToTop(hWndNotepad);
  1388.     SetFocus(hWndNotepad);
  1389.     return TRUE;
  1390.   }
  1391.  
  1392.   MessageBox(hMain, "The notepad can only deal with 64K maximum", 
  1393.              "Warning",  MB_OK);
  1394.  
  1395.   EditBufferSize = MAXBUFSIZE;
  1396.  
  1397.   hWndNotepad = CreateWindow("NotePad",    /* class */
  1398.                              "NotePad",    /* title */
  1399.                              WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_CLIP |
  1400.                              WS_MOVEBOX,
  1401.                              5,2, 60,20,     /* x,y,width,height */
  1402.                              hMain,          /* hParent */
  1403.                              NULLHWND,       /* hMenu */
  1404.                              hInstance,      /* hInst */
  1405.                              0L);            /* lpParam */
  1406.  
  1407.   hEdit = CreateWindow("Edit",         /* class */
  1408.                        NULL,           /* title */
  1409.                        ES_MULTILINE | WS_CHILD,  /* dwStyle */
  1410.                        0,0, 56,16,     /* x,y,width,height */
  1411.                        hWndNotepad,    /* hParent */
  1412.                        NULLHWND,       /* hMenu */
  1413.                        0,              /* hInst */
  1414.                        0L);            /* lpParam */
  1415.  
  1416.   ShowWindow(hWndNotepad, SW_SHOW);
  1417.   UpdateWindow(hWndNotepad);
  1418.   BringWindowToTop(hWndNotepad);
  1419.   SetFocus(hEdit);
  1420.   return TRUE;
  1421. }
  1422.  
  1423.  
  1424. int NotepadOpenFile(BYTE *fname)
  1425. {
  1426.   int          fd;
  1427.   HANDLE       hBuf;
  1428.   LPSTR        pBuf;
  1429.  
  1430.   if (!fname)
  1431.     return FALSE;
  1432.  
  1433.   hBuf = GlobalAlloc(GMEM_MOVEABLE, (DWORD) MAXBUFSIZE);
  1434.   if (hBuf)
  1435.     pBuf = (LPSTR) GlobalLock(hBuf);
  1436.   if (!hBuf || !pBuf)
  1437.   {
  1438.     MessageBox(hMain, "Cannot alloc memory for reading", 
  1439.                "Error", MB_OK | MB_ICONEXCLAMATION);
  1440.     return TRUE;
  1441.   }
  1442.  
  1443.   if ((fd = open((char *) fname, O_RDONLY)) < 0)
  1444.   {
  1445.     GlobalUnlock(hBuf);
  1446.     GlobalFree(hBuf);
  1447.     MessageBox(hMain, "Cannot open file for reading", 
  1448.                "Error", MB_OK | MB_ICONEXCLAMATION);
  1449.     return TRUE;
  1450.   }
  1451.   else
  1452.   {
  1453.     int  len;
  1454.     WORD nBytes;
  1455.     WORD nLeft = MAXBUFSIZE;
  1456.  
  1457.     for (nBytes=0; 
  1458.          nLeft > 0 && (len = _lread(fd, pBuf+nBytes, min(0x7FFF, nLeft))) > 0;
  1459.          nBytes += len)
  1460.       nLeft -= len;
  1461.     *(pBuf + nBytes) = '\0';
  1462.     close(fd);
  1463.     SendMessage(hEdit, WM_SETTEXT, 0, (LONG) pBuf);
  1464.     GlobalUnlock(hBuf);
  1465.     GlobalFree(hBuf);
  1466.   }
  1467.   return TRUE;
  1468. }
  1469.  
  1470.  
  1471. LONG PASCAL NotepadWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
  1472. {
  1473.   char         buf[128];
  1474.   HANDLE       pHandle;
  1475.  
  1476.   switch (message)
  1477.   {
  1478.     case WM_COMMAND    :
  1479.       switch (wParam)
  1480.       {
  1481.         case ID_OPEN:
  1482.           if (DlgOpenFile(NULLHWND, (PSTR) "*.txt", (PSTR) buf))
  1483.             NotepadOpenFile((PSTR) buf);
  1484.           break;
  1485.         case ID_SAVE:
  1486.           return BadCommand();
  1487.         case ID_SAVEAS:
  1488.           return BadCommand();
  1489.         case ID_EXIT:
  1490.           hWndNotepad = NULLHWND;
  1491.           DestroyWindow(hWnd);
  1492.           break;
  1493.  
  1494.         case ID_CUT :
  1495.           SendMessage(hEdit, WM_CUT, 0, 0L);
  1496.           break;
  1497.         case ID_CLEAR:
  1498.           SendMessage(hEdit, WM_CLEAR, 0, 0L);
  1499.           break;
  1500.         case ID_COPY:
  1501.           SendMessage(hEdit, WM_COPY, 0, 0L);
  1502.           break;
  1503.         case ID_PASTE:
  1504.           SendMessage(hEdit, WM_PASTE, 0, 0L);
  1505.           break;
  1506.  
  1507.         case ID_GETLEN :
  1508.           sprintf(buf, "There are %d characters", 
  1509.                   SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0L));
  1510.           MessageBox(hMain, buf, "Text Length", MB_OK);
  1511.           break;
  1512.         case ID_GETLINES:
  1513.           sprintf(buf, "There are %d lines", 
  1514.                   SendMessage(hEdit, EM_GETLINECOUNT, 0, 0L));
  1515.           MessageBox(hMain, buf, "# of Lines", MB_OK);
  1516.           break;
  1517.         case ID_GETHANDLE:
  1518.           pHandle = (HANDLE) SendMessage(hEdit, EM_GETHANDLE, 0, 0L);
  1519.           sprintf(buf, "The edit handle is [%x]", pHandle);
  1520.           MessageBox(hMain, buf, "Get Handle", MB_OK);
  1521.           break;
  1522.       }
  1523.       break;
  1524.  
  1525.     case WM_CLOSE :
  1526.       hWndNotepad = NULLHWND;
  1527.       DestroyWindow(hWnd);
  1528.       return TRUE;
  1529.  
  1530.     default :
  1531.       /* Call the default window procedure for the main window */
  1532.       return DefWindowProc(hWnd, message, wParam, lParam);
  1533.   }
  1534.   return TRUE;
  1535. }
  1536.  
  1537. int BadCommand(VOID)
  1538. {
  1539.   MessageBox(hMain, "This command has not been implemented yet!", 
  1540.              "Error", MB_OK | MB_ICONHAND);
  1541.   return TRUE;
  1542. }
  1543.  
  1544.  
  1545.  
  1546. /****************************************************************************/
  1547. /*                                                                          */
  1548. /* Function : ComboDemo()                                                   */
  1549. /*                                                                          */
  1550. /* Purpose  : Shows all three styles of combo boxes                         */
  1551. /*                                                                          */
  1552. /* Returns  :                                                               */
  1553. /*                                                                          */
  1554. /****************************************************************************/
  1555. #define ID_UDPATH                         1000
  1556. #define ID_BUDPATH                        1001
  1557. #define ID_CBFUTURES                      1002
  1558. #define ID_CBEQUITIES                     1003
  1559. #define ID_CBTICK                         1004
  1560. #define ID_INDICES                        1005
  1561. #define    ID_HOLIDAYS              1006
  1562.  
  1563. VOID ComboDemo(void)
  1564. {
  1565.   MessageBox(hMain,
  1566.             "To pulldown the hidden listbox portion of a combobox,\n\
  1567. click on the combobox arrow icon or press F4 or ALT-GREY-DOWN.",
  1568.                      "Combo box demo", MB_OK);
  1569.   DialogBox(hInstance, "UpdateSettings", hMain, (FARPROC) ComboDialogProc);
  1570. }
  1571.  
  1572. int PASCAL ComboDialogProc(HDLG hDlg, WORD msg, WORD wParam, DWORD lParam)
  1573. {
  1574.   int i;
  1575.  
  1576.   static char *szColors[] =
  1577.   {
  1578.     "Black", "Blue",    "Green",  "Cyan", 
  1579.     "Red",   "Magenta", "Yellow", "White",
  1580.     NULL
  1581.   };
  1582.  
  1583.  
  1584.   (void) lParam;
  1585.  
  1586.   switch (msg)
  1587.   {
  1588.     case WM_INITDIALOG :
  1589.       SendDlgItemMessage(hDlg, ID_CBTICK, WM_SETREDRAW, FALSE, 0L);
  1590.       for (i = 0;  szColors[i];  i++)
  1591.         SendDlgItemMessage(hDlg, ID_CBTICK, CB_ADDSTRING, 0, (DWORD) (LPSTR) szColors[i]);
  1592.       SendDlgItemMessage(hDlg, ID_CBTICK, CB_SETCURSEL, 2, 0L);
  1593.       i = (int) SendDlgItemMessage(hDlg, ID_CBTICK, CB_GETCURSEL, 0, 0L);
  1594.       SendDlgItemMessage(hDlg, ID_CBTICK, WM_SETREDRAW, TRUE, 0L);
  1595.  
  1596.       SendDlgItemMessage(hDlg, ID_CBFUTURES, WM_SETREDRAW, FALSE, 0L);
  1597.       for (i = 0;  szColors[i];  i++)
  1598.         SendDlgItemMessage(hDlg, ID_CBFUTURES, CB_ADDSTRING, 0, (DWORD) (LPSTR) szColors[i]);
  1599.       SendDlgItemMessage(hDlg, ID_CBFUTURES, CB_SETCURSEL, 6, 0L);
  1600.       i = (int) SendDlgItemMessage(hDlg, ID_CBFUTURES, CB_GETCURSEL, 0, 0L);
  1601.       SendDlgItemMessage(hDlg, ID_CBFUTURES, WM_SETREDRAW, TRUE, 0L);
  1602.  
  1603.       SendDlgItemMessage(hDlg, ID_CBEQUITIES, WM_SETREDRAW, FALSE, 0L);
  1604.       for (i = 0;  szColors[i];  i++)
  1605.         SendDlgItemMessage(hDlg, ID_CBEQUITIES, CB_ADDSTRING, 0, (DWORD) (LPSTR) szColors[i]);
  1606.       SendDlgItemMessage(hDlg, ID_CBEQUITIES, CB_SETCURSEL, 2, 0L);
  1607.       i = (int) SendDlgItemMessage(hDlg, ID_CBEQUITIES, CB_GETCURSEL, 0, 0L);
  1608.       SendDlgItemMessage(hDlg, ID_CBEQUITIES, WM_SETREDRAW, TRUE, 0L);
  1609.       return TRUE;
  1610.  
  1611.     case WM_COMMAND :
  1612.       switch (wParam)
  1613.       {
  1614.         case IDOK :
  1615.         case IDCANCEL :
  1616.           EndDialog(hDlg, TRUE);
  1617.           break;
  1618.       }
  1619.       return TRUE;
  1620.   }
  1621.   return FALSE;
  1622. }
  1623.  
  1624.  
  1625. /**********************************************************************
  1626. * HEXCALC.C                            
  1627. *                                                  
  1628. * Converted to Mewel by Sal Ricciardi of PC Magazine
  1629. *
  1630. **********************************************************************/
  1631. int PASCAL CalcDlgProc (HWND, WORD, WORD, DWORD) ;
  1632. DWORD CalcIt (DWORD dwFirstNum, WORD nOperation, DWORD dwNum);
  1633. VOID ShowNumber (HWND hWnd, DWORD dwNumber);
  1634.  
  1635. int Calculator(VOID)
  1636. {
  1637.   static BYTE szAppName[] = "HexCalc" ;
  1638.  
  1639.   if (hWndCalc)
  1640.   {
  1641.     BringWindowToTop(hWndCalc);
  1642.     SetFocus(hWndCalc);
  1643.     return TRUE;
  1644.   }
  1645.  
  1646. MessageBox(NULLHWND,
  1647. "The Calculator is a POPUP window, and will stay in front of all other \
  1648. non-popup windows (like the notepad).",
  1649. "Note", MB_OK);
  1650.  
  1651.   if ((hWndCalc = CreateDialog(hInstance, szAppName, hMain, (FARPROC) CalcDlgProc)) != NULL)
  1652.   {
  1653. //  SetMenu(hWndCalc, LoadMenu(hInstance, (LPSTR) "DlgBoxMenu"));
  1654.     ShowWindow(hWndCalc, SW_SHOW);
  1655.     SetFocus(hWndCalc);
  1656.   }
  1657.   else
  1658.   {
  1659.     MessageBox(hMain, "Could not load calculator", "Error", MB_OK);
  1660.   }
  1661.   return TRUE;
  1662. }
  1663.  
  1664. VOID ShowNumber(HWND hWnd, DWORD dwNumber)
  1665. {
  1666.    BYTE  szBuffer[20] ;
  1667.  
  1668. #ifndef UNIX
  1669.    SetDlgItemText(hWnd, VK_ESCAPE, 
  1670.                     (PSTR) strupr(ltoa(dwNumber, (char *) szBuffer, 16))) ;
  1671. #endif
  1672. }
  1673.  
  1674.  
  1675. DWORD CalcIt(DWORD dwFirstNum, WORD nOperation, DWORD dwNum)
  1676. {
  1677.    switch (nOperation)
  1678.    {
  1679.       case '=' : return dwNum ;
  1680.       case '+' : return dwFirstNum +  dwNum ;
  1681.       case '-' : return dwFirstNum -  dwNum ;
  1682.       case '*' : return dwFirstNum *  dwNum ;
  1683.       case '&' : return dwFirstNum &  dwNum ;
  1684.       case '|' : return dwFirstNum |  dwNum ;
  1685.       case '^' : return dwFirstNum ^  dwNum ;
  1686.       case '<' : return dwFirstNum << dwNum ;
  1687.       case '>' : return dwFirstNum >> dwNum ;
  1688.       case '/' : return dwNum ? dwFirstNum / dwNum : ULONG_MAX ;
  1689.       case '%' : return dwNum ? dwFirstNum % dwNum : ULONG_MAX ;
  1690.       default  : return 0L ;
  1691.    }
  1692. }
  1693.  
  1694. int PASCAL CalcDlgProc(HWND hWnd, WORD iMessage, WORD wParam, DWORD lParam)
  1695. {
  1696.    static BOOL  bNewNumber = TRUE ;
  1697.    static DWORD dwNumber, dwFirstNum ;
  1698.    static short nOperation = '=' ;
  1699.    HWND         hButton ;
  1700.  
  1701.    (void) lParam;
  1702.  
  1703.    switch (iMessage)
  1704.    {
  1705.       case WM_KEYDOWN:               /* left arrow --> backspace */
  1706.          if (wParam != VK_LEFT)
  1707.             break ;
  1708.          wParam = VK_BACK ;                                                       /* fall through */
  1709.  
  1710.       case WM_CHAR:
  1711.          switch (toupper(wParam))
  1712.          {
  1713.             case VK_DOWN:
  1714.             case VK_RIGHT:
  1715.                wParam = VK_TAB;
  1716.                return FALSE;
  1717.  
  1718.             case VK_UP:
  1719.             case VK_LEFT:
  1720.                wParam = VK_BACKTAB;
  1721.                return FALSE;
  1722.  
  1723.             case VK_TAB:
  1724.             case VK_BACKTAB:
  1725.                return FALSE;
  1726.  
  1727.             default:
  1728.                break;
  1729.          }
  1730.  
  1731.          if ((wParam = toupper(wParam)) == VK_RETURN)
  1732.             wParam = (WORD) '=';
  1733.  
  1734.          if ((hButton = GetDlgItem(hWnd, wParam)) != NULL)
  1735.          {
  1736.             SendMessage (hButton, BM_SETSTATE, 1, 0L) ;
  1737.             SendMessage (hButton, BM_SETSTATE, 0, 0L) ;
  1738.             SetFocus (hButton) ;
  1739.          }
  1740.          else
  1741.          {
  1742.             MessageBeep (0) ;
  1743.             break ;
  1744.          }                                                                        /* fall through */
  1745.  
  1746.       case WM_COMMAND:
  1747.          if (wParam == ID_ABOUT)
  1748.          {
  1749.            MessageBox(hWnd, (PSTR) "Calculator Demo",
  1750.                       (PSTR) "About MEWEL", MB_OK | MB_ICONEXCLAMATION);
  1751.            break;
  1752.          }
  1753.          else if (wParam == ID_EXIT)
  1754.          {
  1755.            PostMessage(hWnd, WM_CLOSE, 0, 0L);
  1756.            break;
  1757.          }
  1758.  
  1759.          SetFocus (hWnd) ;
  1760.  
  1761.          if (wParam == VK_BACK)                                                      /* backspace */
  1762.             ShowNumber (hWnd, dwNumber /= 16) ;
  1763.  
  1764.          else if (wParam == VK_ESCAPE)                                                  /* escape */
  1765.             ShowNumber (hWnd, dwNumber = 0L) ;
  1766.  
  1767.          else if (isxdigit (wParam))                                                 /* hex digit */
  1768.          {
  1769.             if (bNewNumber)
  1770.             {
  1771.                dwFirstNum = dwNumber ;
  1772.                dwNumber = 0L ;
  1773.             }
  1774.             bNewNumber = FALSE ;
  1775.  
  1776.             if (dwNumber <= (ULONG_MAX >> 4))
  1777.                ShowNumber (hWnd, dwNumber = 16 * dwNumber + wParam -
  1778.                (isdigit (wParam) ? '0' : 'A' - 10)) ;
  1779.             else
  1780.                MessageBeep (0) ;
  1781.          }
  1782.          else                                                                        /* operation */
  1783.          {
  1784.             if (!bNewNumber)
  1785.                ShowNumber (hWnd, dwNumber =
  1786.                CalcIt (dwFirstNum, nOperation, dwNumber)) ;
  1787.             bNewNumber = TRUE ;
  1788.             nOperation = wParam ;
  1789.          }
  1790.          break ;
  1791.  
  1792.       case WM_CLOSE :
  1793.         hWndCalc = NULLHWND;
  1794.         DestroyWindow(hWnd);
  1795.         break;
  1796.  
  1797.       default :
  1798.          return FALSE;
  1799.    }
  1800.    return TRUE;
  1801. }
  1802.  
  1803.  
  1804. /**************************************************************************/
  1805. /*                                                                        */
  1806. /*  SCRLDEMO.C - demonstration of the usage of scroll bars....            */
  1807. /*                                                                        */
  1808. /**************************************************************************/
  1809. int PrintScrollbarValues(WORD message, WORD wParam, LONG lParam)
  1810. {
  1811.   char *pszMsg;
  1812.   char buf[80];
  1813.   HWND hSB;
  1814.   int  minpos, maxpos, currpos;
  1815.   HDC  hDC;
  1816.   HBRUSH hBrush;
  1817.   RECT   r;
  1818.  
  1819.   (void) message;
  1820.  
  1821.  
  1822.   hSB = HIWORD(lParam);        /* HIWORD(lParam) has the scrollbar handle */
  1823.   currpos = GetScrollPos(hSB, SB_CTL);
  1824.   GetScrollRange(hSB, SB_CTL, &minpos, &maxpos);
  1825.  
  1826.   switch (wParam)
  1827.   {
  1828.     case SB_LINEUP   :
  1829.       SetScrollPos(hSB, SB_CTL, max(currpos-1, minpos), TRUE);
  1830.       currpos = GetScrollPos(hSB, SB_CTL);
  1831.       pszMsg = "SB_LINEUP";
  1832.       break;
  1833.  
  1834.     case SB_LINEDOWN :
  1835.       SetScrollPos(hSB, SB_CTL, min(currpos+1, maxpos), TRUE);
  1836.       currpos = GetScrollPos(hSB, SB_CTL);
  1837.       pszMsg = "SB_LINEDOWN";
  1838.       break;
  1839.  
  1840.     case SB_PAGEUP   :
  1841.       SetScrollPos(hSB, SB_CTL, max(currpos-10, minpos), TRUE);
  1842.       currpos = GetScrollPos(hSB, SB_CTL);
  1843.       pszMsg = "SB_PAGEUP";
  1844.       break;
  1845.  
  1846.     case SB_PAGEDOWN :
  1847.       SetScrollPos(hSB, SB_CTL, min(currpos+10, maxpos), TRUE);
  1848.       currpos = GetScrollPos(hSB, SB_CTL);
  1849.       pszMsg = "SB_PAGEDOWN";
  1850.       break;
  1851.  
  1852.     case SB_THUMBTRACK :
  1853.       pszMsg = "SB_THUMBTRACK";
  1854.       goto do_it;
  1855.     case SB_THUMBPOSITION :
  1856.       pszMsg = "SB_THUMBPOSITION";
  1857.       goto do_it;
  1858.     case SB_ENDSCROLL  :
  1859.       pszMsg = "SB_ENDSCROLL";
  1860. do_it:
  1861.       currpos = LOWORD(lParam);
  1862.       SetScrollPos(hSB, SB_CTL, max(min(currpos, maxpos), minpos), TRUE);
  1863.       currpos = GetScrollPos(hSB, SB_CTL);
  1864.       break;
  1865.   }
  1866.  
  1867.   /*
  1868.     This is the low-level MEWEL way of clearing out a window and writing text 
  1869.     to it. For Windows compatibility, you can do a GetDC, FillRect, TextOut,
  1870.     and ReleaseDC, with SetTextColor and SetBkColor thrown in for good
  1871.     measure.
  1872.   */
  1873.   sprintf(buf, "Msg [%s]   Pos [%3d]  %3d%%     ",
  1874.                        pszMsg, currpos, currpos * 100 / maxpos);
  1875. #if 1
  1876.   WinEraseEOL(hMsgWnd, 0, 0, 0x31);
  1877.   WinPuts(hMsgWnd, 0, 0, (PSTR) buf, 0x31);
  1878. #else
  1879.   hDC = GetDC(hMsgWnd);
  1880.   SetTextColor(hDC, RGB(0, 0, 128));
  1881.   SetBkColor(hDC, RGB(0, 128, 128));
  1882.   hBrush = CreateSolidBrush(RGB(0, 128, 128));
  1883.   GetClientRect(hMsgWnd, (LPRECT) &r);
  1884.   FillRect(hMsgWnd, (LPRECT) &r, hBrush);
  1885.   DeleteObject(hBrush);
  1886.   TextOut(hDC, 0, 0, buf, strlen(buf));
  1887.   ReleaseDC(hMsgWnd, hDC);
  1888. #endif
  1889.   return TRUE;
  1890. }
  1891.  
  1892.  
  1893. /****************************************************************************/
  1894. /*                                                                          */
  1895. /* Function : GraphicsModeDemo                                              */
  1896. /*                                                                          */
  1897. /* Purpose  : Shows how MEWEL can work in graphics mode.                    */
  1898. /*                                                                          */
  1899. /* Returns  :                                                               */
  1900. /*                                                                          */
  1901. /****************************************************************************/
  1902. VOID GraphicsModeDemo(VOID)
  1903. {
  1904.   static int oldMode = -1;
  1905.   static BOOL bGraphics = FALSE;
  1906.  
  1907. #ifdef DOS
  1908.   if (bGraphics)
  1909.   {
  1910.     VidSetBlinking(TRUE);
  1911.     VidSetVideoMode(oldMode);
  1912.     bGraphics = FALSE;
  1913.     CheckMenuItem(GetMenu(hMain), ID_GRAPHICS, MF_UNCHECKED | MF_BYCOMMAND);
  1914.   }
  1915.   else
  1916.   {
  1917.     oldMode = VidGetMode();
  1918.     if (!IsEGA() && !IsVGA())
  1919.     {
  1920.       MessageBox(hMain, "You must have an EGA/VGA monitor for this one",
  1921.                  "Graph Demo", MB_OK | MB_ICONEXCLAMATION);
  1922.       return;
  1923.     }
  1924.     if (GetSystemMetrics(SM_CYSCREEN) > 25)
  1925.     {
  1926.       MessageBox(hMain, "You have to be in 25-line mode for this one",
  1927.                  "Graph Demo", MB_OK | MB_ICONEXCLAMATION);
  1928.       return;
  1929.     }
  1930.  
  1931.     VidSetBlinking(FALSE);
  1932.     VidSetVideoMode(0x10);
  1933.     bGraphics = TRUE;
  1934.     CheckMenuItem(GetMenu(hMain), ID_GRAPHICS, MF_CHECKED | MF_BYCOMMAND);
  1935.   }
  1936. #endif
  1937. }
  1938.  
  1939.  
  1940. /****************************************************************************/
  1941. /*                                                                          */
  1942. /* Function : VideoModeDemo                                                 */
  1943. /*                                                                          */
  1944. /* Purpose  : Toggles MEWEL between 25 and 43/50 line mode.                 */
  1945. /*                                                                          */
  1946. /* Returns  :                                                               */
  1947. /*                                                                          */
  1948. /****************************************************************************/
  1949. VOID VideoModeDemo(VOID)
  1950. {
  1951. #if defined(DOS) || defined(OS2)
  1952.   if (IsEGA() || IsVGA())
  1953.   {
  1954.     ToggleEGA();
  1955.     ChangeMenu(GetMenu(hMain), ID_TOGGLEEGA, 
  1956.                (GetSystemMetrics(SM_CYSCREEN) <= 25) ? "43/50 Line Mode"
  1957.                                                      : "25 Line Mode",
  1958.                0,
  1959.                MF_STRING | MF_BYCOMMAND | MF_CHANGE);
  1960.   }
  1961.   else
  1962.   {
  1963.     MessageBox(NULLHWND, "Sorry. You need an EGA or VGA", "Toggle Demo",
  1964.                MB_OK | MB_ICONEXCLAMATION);
  1965.   }
  1966. #endif
  1967. }
  1968.  
  1969.  
  1970. /****************************************************************************/
  1971. /*                                                                          */
  1972. /* Function : DOSEscape()                                                   */
  1973. /*                                                                          */
  1974. /* Purpose  : Demo of the ability to spawn a program with the entirety      */
  1975. /*            of MEWEL swapped out to EMS or to disk                        */
  1976. /* Returns  :                                                               */
  1977. /*                                                                          */
  1978. /****************************************************************************/
  1979. VOID DOSEscape(VOID)
  1980. {
  1981. #ifndef UNIX
  1982.   MessageBox(hMain,
  1983. "This will exec a copy of COMMAND.COM two times.\n\
  1984. The first time, the entire MEWEL session will be swapped to disk or\n\
  1985. to EMS, and the second time, COMMAND.COM will be spawned without swapping\n\
  1986. the MEWEL session out.  Type EXIT at the DOS prompt to return to MEWEL.",
  1987.              (PSTR) "DOS Demo", MB_OK);
  1988.  
  1989. #ifndef DOS286X
  1990.   MessageBox(hMain, "Execing with swapping", "Swap", MB_OK);
  1991.   WinExec(NULL, TRUE);
  1992. #endif
  1993.  
  1994.   MessageBox(hMain, "Execing without swapping", "Swap", MB_OK);
  1995.   WinExec(NULL, FALSE);
  1996. #endif
  1997. }
  1998.  
  1999.  
  2000. /****************************************************************************/
  2001. /*                                                                          */
  2002. /* Function : memavail()                                                    */
  2003. /*                                                                          */
  2004. /* Purpose  : Returns the amount of available memory.                       */
  2005. /*                                                                          */
  2006. /* Returns  :                                                               */
  2007. /*                                                                          */
  2008. /****************************************************************************/
  2009. #ifdef DOS
  2010. /*
  2011.   For the 386 DOS Extenders, we need to redefine the way that int86()
  2012.   is called.
  2013. */
  2014. #if defined(__WATCOMC__) && defined(__386__)
  2015. #define ax  eax
  2016. #define bx  ebx
  2017. #define cx  ecx
  2018. #define dx  edx
  2019. #define int86  int386
  2020. #endif
  2021.  
  2022. long memavail(VOID)
  2023. {
  2024.   union REGS regs;
  2025.  
  2026.   regs.h.ah = 0x48;
  2027.   regs.x.bx = 0xFFFF;
  2028.   int86(0x21, ®s, ®s);
  2029.   return(16L * regs.x.bx);
  2030. }
  2031. #endif
  2032.  
  2033.